package com.edu.web.servlet;

import com.alibaba.fastjson2.JSON;
import com.edu.entity.PageBean;
import com.edu.entity.User;
import com.edu.entity.Vehicles;
import com.edu.service.UserService;
import com.edu.service.VehiclesService;
import com.edu.service.imlp.UserServiceImpl;
import com.edu.service.imlp.VehiclesServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/selectUserServlet")
public class SelectUserServlet extends HttpServlet {
    UserService userService = new UserServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取id
        int id = Integer.parseInt(req.getParameter("id") == null ? "1" : req.getParameter("id"));
        //查询
        User user = userService.queryByIdUser(id);
        //响应
        String jsonString = JSON.toJSONString(user);
        PrintWriter writer = resp.getWriter();
        writer.print(jsonString);
        writer.flush();
        writer.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
